package com.cxy.controller;

import com.cxy.mapper.EmpMapper;
import com.cxy.pojo.Dept;
import com.cxy.pojo.Result;
import com.cxy.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;


    /**
     * 查看部门信息
     */
    @GetMapping("/depts")
    public Result list(){
        log.info("查找部门信息...");

        List<Dept> deptList = deptService.list();
        return Result.success(deptList);
    }

    /**
     * 删除部门
     */
    @DeleteMapping("/depts/{id}")
    public Result delete(@PathVariable Integer id) throws Exception {
        log.info("删除部门信息");

        deptService.delete(id);


        return Result.success();
    }

    /**
     * 新增部门
     */
    @PostMapping("/depts")
    public Result insert(@RequestBody Dept dept){
        log.info("新增部门");

        deptService.insert(dept);
        return Result.success();
    }


}
